let arr1=[1,2,3,4]
let arr2=[1,2,3]
let arr3=[1,2,3,4,5]
let arr4=[1,2,3,4,5,6,7,8,9]

function a(arr){
    let len = arr.length;
    
    if(len<4){
        return arr
    }else{
        let mode = len % 2
        let aArr=[]
        let tradeS =Math.floor (len / 2)
        if(mode==0){
            aArr=[arr[0],arr[tradeS - 1],arr[tradeS],arr[len-1]]
           
        }else{
            aArr = [arr[0],arr[tradeS],arr[len-1]]
        }
        return aArr;
    }
}

console.log(a(arr1))
console.log(a(arr2))
console.log(a(arr3))
console.log(a(arr4))